package com.atguigu.gmall.user.service.impl;

import com.atguigu.gmall.model.user.UserInfo;
import com.atguigu.gmall.user.mapper.UserInfoMapper;
import com.atguigu.gmall.user.service.UserService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

/**
 * @author Fxz
 * @version 1.0
 * @date 2022-02-15 14:08
 */
@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {

	private final UserInfoMapper userInfoMapper;

	/**
	 * 用户登录
	 */
	@Override
	public UserInfo login(UserInfo userInfo) {
		return userInfoMapper
				.selectOne(Wrappers.<UserInfo>query().lambda().eq(UserInfo::getLoginName, userInfo.getLoginName())
						.eq(UserInfo::getPasswd, DigestUtils.md5DigestAsHex(userInfo.getPasswd().getBytes())));
	}

}
